package com.title5;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @Author milian
 * @Date 2021/7/31 0031 21:20
 */
public class title5 {
    public static void main(String[] args) throws IOException {
        String[] str = {"hello","world","java","heiheihei"};
        StringBuilder sb = new StringBuilder("");
        for (String s : str) {
            sb.append(s);
        }
        Map<String, Integer> map = new HashMap<>();
        String[] split = sb.toString().split("");
        for (int i = 0; i < split.length; i++) {
            if (map.containsKey(split[i])){
                map.put(split[i],map.get(split[i])+1 );
        }else {
                map.put(split[i],1 );
            }
    }
        FileOutputStream fileOutputStream = new FileOutputStream("count.txt");
        Set<String> set = map.keySet();
        for (String s : set) {
            fileOutputStream.write(s.getBytes());
            fileOutputStream.write(58);
            fileOutputStream.write(map.get(s).toString().getBytes());
            fileOutputStream.write("\r\n".getBytes());
        }
            fileOutputStream.close();
    }
}
